<template>
  <div class="AddOrUpdate_main add_container column_two">
    <div class="main_main">
      <el-form ref="form" :model="formData" :rules="rules" :inline="true">
        <el-form-item label="审批意见" class="double">
          <el-input
            v-model="formData.approvalContent"
            type="textarea"
            placeholder="请输入"
          />
        </el-form-item>
      </el-form>
    </div>
    <div class="main_bottom">
      <el-button type="cancel" @click.stop="cancel">取消</el-button>
      <el-button v-if="formData.approvalStatus=='2'" type="reject" @click.stop="onSubmit()">确认驳回</el-button>
      <el-button v-if="formData.approvalStatus=='1'" @click.stop="onSubmit()">确认通过</el-button>
    </div>
  </div>
</template>

<script>
import { review } from '@/api/saleManage/saleReview'
export default {
  name: 'AddOrUpdate',
  props: {
    layerid: {},
    defaultValue: {}
  },
  data() {
    return {
      formData: {
        taskNo: '',
        approvalContent: '',
        approvalStatus: ''
      },
      mainId: 'id',
      rules: {
      }
    }
  },
  mounted() {
    Object.keys(this.defaultValue).forEach((key) => {
      this.formData[key] = this.defaultValue[key]
    })
    this.formData.approvalContent = ''
  },
  methods: {
    // 提交
    onSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          review(this.formData).then((res) => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.$layer.close(this.layerid) // 关闭弹框
            this.$parent.refresh() // 调用父组件的刷新方法
          })
        }
      })
    },
    cancel() {
      this.$layer.close(this.layerid) // 关闭弹框
    }
  }
}
</script>

<style lang="less" scoped>
</style>
